<template>
  <div class="content">
        <ul class="record-list"
            v-infinite-scroll="loadMore"
            infinite-scroll-disabled="loading"
            infinite-scroll-distance="10"
            :infinite-scroll-immediate-check="true">
            <li v-for="(item,index) in list" :key="index" class="record-list-item">
                <router-link :to='`/record_details/${item.order_id}`'>
                    <h5>{{item.goods_name}}</h5>
                    <p>
                        <span class="time">兑换时间：{{item.create_time}}</span>
                        <span class="credits">-{{item.scores}}积分</span>
                    </p>
                </router-link>
            </li>
        </ul>
        <p class="page-infinite-loading" v-show="loading">
            <mt-spinner type="fading-circle" color="#23ab1b" class="spinner"></mt-spinner>
            加载中...
        </p>
        <p class="no-data" v-if="!loading&&this.list.length===0">暂无记录</p>
        <p class="no-data" v-if="no_more&&this.list.length>0">没有更多了</p>
  </div>
</template>

<script>
import { apiPost } from "src/common/api.js";
export default {
  name: "record-list",
  data() {
    return {
      loading: false,
      no_more:false,
      list: []
    };
  },
  mounted() {
    this.loadMore()
  },
  methods: {
    loadMore() {
      if(this.loading){
        return false
      }
      this.loading = true;
      apiPost('orders',{start:this.list.length,limit:10}).then((res)=>{
        if(res.status === 0){
          if(res.data.length>0){
            this.list = this.list.concat(res.data)
          }else{
            this.no_more = true
          }
        }else{
          console.log(res.msg)
        }
      })
      .then(()=>{
        this.loading = false;
      })
    }
  }
};
</script>

<style lang="scss" scoped>
.record-list {
  li.record-list-item {
    padding: 15px;
    background: #fff;
    border-bottom: 1px solid #d2d2d2;
    margin-bottom: 10px;
    a {
      color: #333;
      h5 {
        font-size: 16px;
        font-weight: 400;
      }
      p {
        display: flex;
        justify-content: space-between;
        font-size: 13px;
        span.time {
          display: block;
          flex: auto;
          margin-right: 1em;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        span.credits {
          display: block;
          flex: none;
          overflow: hidden;
          color: #23ab1b;
          text-overflow: ellipsis;
        }
      }
    }
  }
}
.page-infinite-loading {
  text-align: center;
  line-height: 37px;
  .spinner {
    display: inline-block;
    width: 28px;
    vertical-align: middle;
  }
}
.no-data{
  padding: 10px;
  text-align: center;
  color: #666;
}
</style>

